Fix future prices incorrectly affecting lowest recent price calculation #458
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The
PublicOffer::Productlowest recent price calculation was not properly handling future prices. Thefind_border_eventmethod inRegisterLowestPricecould potentially select future price events as "border events", which would then be included in the lowest price comparison despite being future prices that shouldn't affect current pricing.Root Cause
The issue was in the
find_border_eventmethod:This method looks for events that are not in the recent period (last 30 days) to use as a baseline for price comparison. However, it only checked
!recent_event?without explicitly excluding future events. While future events are typically considered "recent" by the current logic, edge cases or configuration changes could make future events qualify as non-recent, causing them to be incorrectly selected as border events and included in the lowest price calculation.Solution
Updated the
find_border_eventmethod to explicitly exclude future events:This ensures that:
Testing
Added a comprehensive test case
test_future_price_not_selected_as_border_event_even_when_lowestthat verifies future prices are never selected as border events, even when they represent the lowest price value.The existing tests
test_ignores_future_pricesandtest_takes_last_event_when_no_events_in_last_30_dayscontinue to pass, confirming the fix doesn't break existing functionality.Impact
recent_event?logic changesFixes #435
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.